package test;

/**
 * @author suwy
 * @todo translate ASCII to String and String to ASCII
 */
public class TranslateASCII {

	private static String str = "新年快乐";
	private static String ascii = "#22307;#35806;#24555;#20048;";
	
	public static void main(String[] args) {
//		System.out.println(translateASCII(str));
		System.out.println(translateString(ascii));
	}

	public static String translateASCII(String str) {
		char[] chars = str.toCharArray();
		StringBuilder strGroup = new StringBuilder();
		for(int i = 0; i < chars.length; i++) {
			//System.out.println(chars[i] + "  " + (int) chars[i]);
			strGroup.append("#" + (int) chars[i] + ";");
		}
		return strGroup.toString();
	}
	
	public static String translateString(String accii) {
		StringBuilder strGroup = new StringBuilder();
		String[] chars = accii.replace("#", "").split(";");
		for(int i = 0; i < chars.length; i++) {
			strGroup.append((char) Integer.parseInt(chars[i]));
		}
		return strGroup.toString();
	}
}